package com.jfree.nettyshow.entity;

import io.netty.channel.Channel;

import java.io.Serializable;

public class Session implements Serializable {

    private String sessionId;

    private Channel channel;

    /**
     * 最后通信时间
     */
    private Long lastAccessTime;

    /**
     * 是否认证通过
     */
    private boolean isCheck;

    /**
     * 最近一次服务端发送消息失败时间
     */
    private Long lastWriteErrTime;

    private HeartEnum heartStatus = HeartEnum.NONE;


    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public Channel getChannel() {
        return channel;
    }

    public void setChannel(Channel channel) {
        this.channel = channel;
    }

    public Long getLastAccessTime() {
        return lastAccessTime;
    }

    public void setLastAccessTime(Long lastAccessTime) {
        this.lastAccessTime = lastAccessTime;
    }

    public boolean isCheck() {
        return isCheck;
    }

    public void setCheck(boolean check) {
        isCheck = check;
    }

    public Long getLastWriteErrTime() {
        return lastWriteErrTime;
    }

    public void setLastWriteErrTime(Long lastWriteErrTime) {
        this.lastWriteErrTime = lastWriteErrTime;
    }

    public HeartEnum getHeartStatus() {
        return heartStatus;
    }

    public void setHeartStatus(HeartEnum heartStatus) {
        this.heartStatus = heartStatus;
    }

    @Override
    public String toString() {
        return "Session{" +
                "sessionId='" + sessionId + '\'' +
                ", channel=" + channel +
                ", lastAccessTime=" + lastAccessTime +
                ", isCheck=" + isCheck +
                ", lastWriteErrTime=" + lastWriteErrTime +
                '}';
    }

    /**
     * 心跳检测异常次数，第三次关闭连接
     */
    enum HeartEnum {
        NONE, ONE, TWO, THREE;
    }
}
